import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'
import Index from '@/views/index'
import Cloud from '@/views/Cloud'
import Login from '@/views/Login'
import Download from '@/views/RemoteUpload'
import Admin from '@/views/Admin'
import AdminLogin from '@/views/AdminLogin'
import SysInfo from '@/views/admin/SysInfo'
import DDNSCore from '@/views/admin/DDNSCore'
import UserCloud from '@/views/admin/cloud'
import SysLog from '../views/admin/SysLog'

const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Index',
    component: Index
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/remoteDownload',
    name: 'Download',
    component: Download
  },
  {
    path: '/cloud',
    name: 'Cloud',
    component: Cloud
  },
  {
    path: '/cloud/**',
    name: 'Cloud-path',
    component: Cloud
  },
  {
    path: '/admin',
    name: 'Admin',
    component: Admin,
    children: [{
      path: 'sysInfo',
      component: SysInfo
    }, {
      path: 'ddns',
      component: DDNSCore
    }, {
      path: 'cloud',
      component: UserCloud
    }, {
      path: 'log',
      component: SysLog
    }, {
      path: '',
      redirect: '/admin/sysInfo'
    }]
  },
  {
    path: '/adminLogin',
    name: 'AdminLogin',
    component: AdminLogin
  },
  {
    path: '*',
    redirect: '/'
  }
]

const router = new VueRouter({
  // mode: 'history',
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

export default router
